<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#box{
				background-color: pink;
				width: 100px;
				height: 100px;
				position: absolute;
				top: 50px;
			}
		</style>
	</head>
	<body>
		<button type="button" id="btn">开始</button>
		<div id="box">
			
		</div>
	</body>
	<script type="text/javascript">
		var btn = document.getElementById('btn')
		var box = document.getElementById('box')
		var timer = null;
		btn.onclick = function(){
			clearInterval(timer);
			 timer = setInterval(function(){
				if(box.offsetLeft > 500){
					clearInterval(timer)
				}else{
					box.style.marginLeft = box.offsetLeft + 1 + 'px'
				}
			},10)
		}
	</script>
</html>
